from time import sleep

from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select


def add_order(driver,ordername,customer,medicine,nums):
    driver.find_element(By.CSS_SELECTOR,
                        '#root > aside > '
                        'section > ul > li:nth-child(4) '
                        '> a > span').click()
    driver.find_element(By.CSS_SELECTOR,'#root > div > '
                                        'section.content.container-fluid > '
                                        'div.col-lg-12.col-md-12.col-sm-12.add-one-area '
                                        '> button').click()
    sleep(1)
    driver.find_element(By.CSS_SELECTOR,'#root > div > section.content.container-fluid '
                                        '> div.col-lg-12.col-md-12.col-sm-12.add-one-area >'
                                        ' div.col-lg-8.col-md-8.col-sm-8 > div:nth-child(1) '
                                        '> input').send_keys(ordername)
    cus=Select(driver.find_element(By.CSS_SELECTOR,'#root > div > section.content.container-fluid '
                                                      '> div.col-lg-12.col-md-12.col-sm-12.add-one-area '
                                                      '> div.col-lg-8.col-md-8.col-sm-8 > div:nth-child(2) '
                                                      '> select'))
    cus.deselect_all()
    cus.select_by_visible_text(customer)
    medic=Select(driver.find_element(By.CSS_SELECTOR,'#root > div > section.content.container-fluid > '
                                                     'div.col-lg-12.col-md-12.col-sm-12.add-one-area > '
                                                     'div.col-lg-8.col-md-8.col-sm-8 > div:nth-child(3) '
                                                     '> select'))
    medic.deselect_all()
    medic.select_by_visible_text(medicine)
    driver.find_element(By.CSS_SELECTOR,'#root > div > section.content.container-fluid > '
                                                   'div.col-lg-12.col-md-12.col-sm-12.add-one-area > '
                                                   'div.col-lg-8.col-md-8.col-sm-8 > div:nth-child(3) > '
                                                   'div > input[type=number]').send_keys(nums)
    sleep(1)
    driver.find_element(By.CSS_SELECTOR,'#root > div > section.content.container-fluid > '
                                        'div.col-lg-12.col-md-12.col-sm-12.add-one-area > '
                                        'div.col-lg-12.col-md-12.col-sm-12 >'
                                        ' button:nth-child(1)').click()
